package com.easymin.daijia.server.ali;

import com.sun.tools.internal.jxc.ap.Const;
import com.ybkj.daijia.serverUtils.IOUtils;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

/**
 * @author zhyu
 * @date 2019/12/24 15:28
 * 自定义模板接口 有效的模板都还没有建立好
 * 这儿有两M限制
 */
public class OrcUserDefined {
    public static void main(String[] args) {
        String host = "https://ocrdiy.market.alicloudapi.com";
        String path = "/api/predict/ocr_sdt";
        String method = "POST";
        Map<String, String> headers = new HashMap();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + Constant.APPCODE);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        Map<String, String> querys = new HashMap();
        String str = IOUtils.readFileToBase64(Constant.BASE_PATH + "q4.jpg");
        if (str != null) {
            String bodys = "{\"image\":\"" + str.replaceAll("\r|\n", "") + "\",\"configure\":{\"template_list\": ["
                + "\"a3d0b1e3-dc42-42ea-a201-6391715859451577257232\","
                + "\"9515bb83-4224-4842-ac7c-596b02fa15cc1577257959\","
                + "\"467cce60-6fb5-444a-a6cc-33ac1a5428211577258266\""
                + "]}}" ;
            try {
                HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
                //获取response的body
                System.out.println(response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
